#ifndef  __HAL_IO_SPI_H__
#define  __HAL_IO_SPI_H__

//----------------------------------------------------------------------------------
//   Common Macros
//----------------------------------------------------------------------------------
#define HAL_IO_SPI_CS_DEASSERT  MCU_IO_SET(IO_SPI_CSN_PORT, IO_SPI_CSN_PIN)
#define HAL_IO_SPI_CS_ASSERT    MCU_IO_CLR(IO_SPI_CSN_PORT, IO_SPI_CSN_PIN)
#define HAL_IO_SPI_SOMI_VAL     MCU_IO_GET(IO_SPI_MISO_PORT, IO_SPI_MISO_PIN)
#define HAL_IO_SPI_BEGIN        st(HAL_IO_SPI_CS_ASSERT; while(HAL_IO_SPI_SOMI_VAL);)
#define HAL_IO_SPI_END          st(HAL_IO_SPI_CS_DEASSERT;)


#define HAL_IO_SPI_WAIT_RXFIN   __no_operation()
#define HAL_IO_SPI_WAIT_TXFIN   __no_operation()
#define HAL_IO_SPI_WAIT_TXBUF   __no_operation()
#define HAL_IO_SPI_RXBUF
#define HAL_IO_SPI_TXBUF
#define HAL_IO_SPI_TXBUF_SET(x) halSpiBitbangOut((x))

INT8U halSpiBitbangOut(INT8U data);
INT8U halSpiBitbangIn(void);

void   halIOSpiInit(INT8U clockrate);
INT8U  halIOSpiWrite(INT8U addr, const INT8U* data, INT16U length);
INT8U  halIOSpiRead(INT8U addr, INT8U* data, INT16U length);
INT8U  halIOSpiStrobe(INT8U cmd);

#endif

